package com.dongdongsongcan.app.adapter;

import java.util.List;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.dongdongsongcan.app.R;
import com.dongdongsongcan.app.control.bean.RecommendAdData.RecommendAd;
import com.dongdongsongcan.app.model.api.ApiUrl;
import com.su.dolphin.core.proxy.ImageLoader;

public class AutoPagerAdapter extends PagerAdapter {
	public List<RecommendAd> mList;
	private Context mContext;

	public AutoPagerAdapter(Context context) {
		this.mContext = context;

	}

	public void setData(List<RecommendAd> imageIdList) {
		this.mList = imageIdList;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		if (mList != null)
			return Integer.MAX_VALUE;
		else
			return 0;
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0.equals(arg1);
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View) object);
	}

	@Override
	public Object instantiateItem(ViewGroup container, final int position) {
		RecommendAd reommendAd = mList.get(position % mList.size());
		View convertView = View.inflate(mContext,
				R.layout.layout_recommendad_page, null);
		ImageView main_recommend_ad_img = (ImageView) convertView
				.findViewById(R.id.main_recommend_ad_img);
		ImageLoader.i().loadImage(main_recommend_ad_img, reommendAd.getImg(),
				R.drawable.ic_launcher);
		container.addView(convertView, 0);
		convertView.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View view) {
				// DramaDetailActivity.start(mContext,
				// mList.get(position % mList.size()).resId);
			}
		});
		return convertView;
	}

}
